package com.hejielife.twophasetermination3;

/**
 * 2019年8月2日 下午4:58:14
 * 
 * @author hejielife
 * @despribe GracefulThread
 */

public class GracefulThread extends Thread {
	private volatile boolean shutdownRequested = false;

	public final void shutdownRequest() {
		shutdownRequested = true;
		interrupt();
	}

	public final boolean isShutdownRequested() {
		return shutdownRequested;
	}

	public final void run() {
		try {
			while (!shutdownRequested) {
				doWork();
			}
		} catch (InterruptedException e) {
		} finally {
			doShutdown();
		}
	}

	protected void doWork() throws InterruptedException {
	}

	protected void doShutdown() {
	}
}
